package com.mg.demo;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Toast;

import com.ushaqi.zhuishushenqi.OfflineBook;
import com.ushaqi.zhuishushenqi.OfflineBookCallBack;
import com.ushaqi.zhuishushenqi.ZSPlugin;

import java.util.List;

public class MyBooListActivity extends Activity {

    private RecyclerView mRecyclerView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mRecyclerView = (RecyclerView) View.inflate(this, R.layout.activity_my_books, null);
        LinearLayoutManager ms = new LinearLayoutManager(this);
        ms.setOrientation(LinearLayoutManager.HORIZONTAL);// 设置 recyclerview 布局方式为横向布局
        mRecyclerView.setLayoutManager(ms);

        final BookListAdapter adapter = new BookListAdapter(this, getIntent().getStringExtra("ticket"));
        mRecyclerView.setAdapter(adapter);
        ZSPlugin.get().getOfflineBooks(new OfflineBookCallBack() {
            @Override
            public void onLoadSuccess(List<OfflineBook> books) {
                if (!books.isEmpty()) {
                    adapter.addBooks(books);
                }
            }

            @Override
            public void onLoadFailure() {
                Toast.makeText(getApplicationContext(), "获取离线数据失败", Toast.LENGTH_SHORT).show();
            }
        });

        setContentView(mRecyclerView);


    }


}
